<script setup lang="ts">
import {ref} from "vue";
import {studentLogin} from "@/http/logIn/logIn";
import {showFailToast, showSuccessToast} from "vant";
import router from "@/router";
import {Tokens} from "@/stores/token";
//登录请求


const username = ref('');
const password = ref('');

const store=Tokens()
const onSubmit = (values) => {
    // console.log('submit', values);
    studentLogin(values).then(res => {
        // console.log(res)
        if (res.code===200) {
           showSuccessToast('登录成功')
            router.push('/gerenzhongxin')
           store.setToken(res.token)
            store.isLogIn=true
        }else {
            showFailToast(res.msg)
        }
    })
};
const active = ref(0);
</script>

<template>
<div>
    <div class="Background">
        <div class="cente">
            <van-tabs v-model:active="active">
                <van-tab title="密码登录">
                    <van-form @submit="onSubmit">
                        <van-cell-group inset>
                            <van-field
                                v-model="username"
                                name="stuNum"
                                label="学号"
                                placeholder="请输入您的学号"
                                :rules="[{ required: true, message: '请填写学号' }]"
                            />
                            <van-field
                                v-model="password"
                                type="password"
                                name="password"
                                label="密码"
                                placeholder="请输入密码"
                                :rules="[{ required: true, message: '请填写密码' }]"
                            />
                        </van-cell-group>
<!--                        <router-link to="/gerenzhongxin">-->
                        <div style="margin: 16px;">
                            <van-button round block type="primary" native-type="submit">
                                登录
                            </van-button>
                        </div>
<!--                        </router-link>-->
                    </van-form>
                </van-tab>
                <van-tab title="验证码登录"></van-tab>
            </van-tabs>
        </div>
    </div>

</div>
</template>

<style scoped lang="less">
.Background{
    height: 696px;
    width: 100%;
    padding-top: 200px;
    background-size: 100% 100%;
    background-image: url("../../../public/u=2611241748,2779723370&fm=253&fmt=auto&app=138&f=JPEG.webp");
    .cente{
        height: 235px;
        border-radius: 20px;
        padding: 20px;
        //box-sizing: border-box;
        background-color: white;
    }
}
</style>